import request from '@/utils/request'

// 查询折扣策略列表
export function listStrategy(query) {
  return request({
    url: '/manage/strategy/list',
    method: 'get',
    params: query
  })
}

// 查询有效的策略列表
export function listActiveStrategy(query) {
  return request({
    url: '/manage/strategy/activeList',
    method: 'get',
    params: query
  })
}

// 根据设备ID查询适用的策略
export function getStrategiesByDeviceId(deviceId) {
  return request({
    url: '/manage/strategy/device/' + deviceId,
    method: 'get'
  })
}

// 查询折扣策略详细
export function getStrategy(id) {
  return request({
    url: '/manage/strategy/' + id,
    method: 'get'
  })
}

// 新增折扣策略
export function addStrategy(data) {
  return request({
    url: '/manage/strategy',
    method: 'post',
    data: data
  })
}

// 修改折扣策略
export function updateStrategy(data) {
  return request({
    url: '/manage/strategy',
    method: 'put',
    data: data
  })
}

// 删除折扣策略
export function delStrategy(id) {
  return request({
    url: '/manage/strategy/' + id,
    method: 'delete'
  })
}

// 分配策略给设备
export function assignDevicesToStrategy(data) {
  return request({
    url: '/manage/strategy/assignDevices',
    method: 'post',
    data: data
  })
}

// 取消策略与设备的关联
export function unassignDevicesFromStrategy(data) {
  return request({
    url: '/manage/strategy/unassignDevices',
    method: 'post',
    data: data
  })
}

// 导出折扣策略
export function exportStrategy(query) {
  return request({
    url: '/manage/strategy/export',
    method: 'post',
    data: query
  })
}